package com.example.uniappspringbootstartweb.service.Imp;

import com.example.uniappspringbootstartweb.entity.Content;

import com.example.uniappspringbootstartweb.mapper.ContentRepository;
import com.example.uniappspringbootstartweb.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author DELL
 */
@Service
public class ContentServiceImpl implements ContentService {

    @Autowired
    private ContentRepository contentRepository;
    @Override
    public List<Content> getAllContents() {
        List<Content> all = contentRepository.findAll();
        System.out.println(all.toString());
        return contentRepository.findAll();
    }
    @Override
    public Content saveContent(Content content) {
        return contentRepository.save(content);
    }
    @Override
    public Content getContentById(Long id) {
        Optional<Content> optionalContent = contentRepository.findById(id);
        return optionalContent.orElse(null);
    }
    @Override
    public void deleteContent(Long id) {

    }


    @Override
    public List<Content> getContentByTab(String tab) {
        return contentRepository.findByTab(tab);
    }

    @Override
    public List<Content> searchContents(String query) {
        return contentRepository.findByTitleContainingIgnoreCase(query);
    }

    @Override
    public Optional<Content> getContentByIdAndTab(Long id, String tab) {
        return contentRepository.findByIdAndTab(id, tab);
    }
}



